﻿<UserControl x:Class="StockholmsStad.Windows.UI.Modules.Minister.Views.MinisterListView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:converters="clr-namespace:StockholmsStad.Windows.UI.Infrastructure.Converters;assembly=StockholmsStad.Windows.UI.Infrastructure"
    xmlns:customControls="clr-namespace:StockholmsStad.Windows.UI.Infrastructure.Controls;assembly=StockholmsStad.Windows.UI.Infrastructure"
    xmlns:Controls="clr-namespace:StockholmsStad.Windows.UI.Infrastructure.Controls;assembly=StockholmsStad.Windows.UI.Infrastructure"
    xmlns:Views="clr-namespace:StockholmsStad.Windows.UI.Modules.Minister.Views">
    <UserControl.Resources>
        <converters:DateTimeToDateString x:Key="dateTimeConverter" />
        <converters:NullableDateTimeToVisibilityConverter x:Key="visibilityConverter" />


        <Style x:Key="showRegisterMenuItem" TargetType="{x:Type FrameworkElement}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Views:MinisterListView},Path=HasMinisterServices}" Value="False}">
                    <Setter Property="Visibility" Value="Collapsed"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <GroupBox Header="Sök förrättare" BorderBrush="#FF0F68A6" Background="Transparent" BorderThickness="1,1,1,1" Margin="5,5,5,10">

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid Grid.Row="0" Grid.Column="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <Label x:Name="lblPartOfName" Content="Del av namn:" Grid.Column="0" Grid.Row="0" />
                <Label x:Name="lblMinister" Content="Förordnandedatum till/från:" Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="3" />

                <TextBox x:Name="tbPartOfName" Text="" Width="140" Margin="0,0,5,0" Grid.Column="0" Grid.Row="1" />
                <Controls:DateTimePicker x:Name="dpStartDate" Margin="3,0,2,0" Grid.Column="1" Grid.Row="1" SelectedDateChanged="dpStartDate_SelectedDateChanged" />
                <Polyline Points="0,20 0,20 10,0" Stroke="Gray" StrokeThickness="1" Margin="5,0,5,0" Grid.Column="2" Grid.Row="1" VerticalAlignment="Center" />
                <Controls:DateTimePicker x:Name="dpEndDate" Margin="0,0,5,0" Grid.Column="3" Grid.Row="1" SelectedDateChanged="dpEndDate_SelectedDateChanged" />
                <customControls:ExtendedRadioButton x:Name="rbActive" Content="Aktiva" Margin="5,0,5,0" Padding="5,0,0,0" VerticalAlignment="Center" Grid.Column="4" Grid.Row="1" IsCheckedReal="True" />
                <customControls:ExtendedRadioButton x:Name="rbNonActive" Content="Ej aktiva" Margin="5,0,5,0" Padding="5,0,0,0" VerticalAlignment="Center" Grid.Column="5" Grid.Row="1" IsCheckedReal="False" />
                <Button x:Name="btnSearch" Content="Sök" Margin="5,0,0,0" Grid.Column="6" Grid.Row="1" Click="btnSearch_Click" />
            </Grid>

            <ListView Grid.Row="1" Grid.Column="0" x:Name="listViewMinisters" Margin="0,10,0,0" MinHeight="100" MaxHeight="100"
                      ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto"
                      ItemsSource="{Binding}" SelectionChanged="listViewMinister_SelectionChanged" SelectedIndex="0">
                <ListView.ContextMenu>
                    <ContextMenu>
                        <MenuItem x:Name="menuPrint" Header="Skriv ut">
                            <MenuItem.Style>
                                <Style TargetType="{x:Type MenuItem}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding HasMinisterServices}" Value="False">
                                            <Setter Property="Visibility" Value="Collapsed" />
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding MinisterServiceTimeBlocks.MinisterServiceTimeBlocks}" Value="{x:Null}">
                                            <Setter Property="Visibility" Value="Collapsed" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </MenuItem.Style>
                            <MenuItem x:Name="MenuItemMarriageRegister" Header="Vigselförteckning" Command="{Binding PrintMinisterRegisterCommand}" >
                                <MenuItem.Style>
                                    <Style TargetType="{x:Type MenuItem}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding HasMinisterServices}" Value="False">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </MenuItem.Style>
                                <MenuItem.Icon>
                                    <Image Source="/StockholmsStad.Windows.UI;component/Resources/Images/print.png"></Image>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem x:Name="MenuItemMarriageService" Header="Tjänstgöringslista" Command="{Binding PrintMinisterServiceCommand}" >
                                <MenuItem.Style>
                                    <Style TargetType="{x:Type MenuItem}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding MinisterServiceTimeBlocks.MinisterServiceTimeBlocks}" Value="{x:Null}">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </MenuItem.Style>
                                <MenuItem.Icon>
                                    <Image Source="/StockholmsStad.Windows.UI;component/Resources/Images/print.png"></Image>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem x:Name="MenuItemMarriageReimbursement" Header="Arvode" Click="MenuItemMarriageReimbursement_Click">
                                <MenuItem.Style>
                                    <Style TargetType="{x:Type MenuItem}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding HasMinisterServices}" Value="False">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </MenuItem.Style>
                                <MenuItem.Icon>
                                    <Image Source="/StockholmsStad.Windows.UI;component/Resources/Images/print.png"></Image>
                                </MenuItem.Icon>
                            </MenuItem>
                        </MenuItem>
                    </ContextMenu>
                </ListView.ContextMenu>
                <ListView.View>
                    <GridView ColumnHeaderContainerStyle="{DynamicResource GridViewColumnHeaderStyle1}" AllowsColumnReorder="False">
                        <GridView.Columns>
                            <GridViewColumn Header="Namn">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding FirstName}" VerticalAlignment="Top" HorizontalAlignment="Left" 
                                                       TextWrapping="NoWrap" />
                                            <TextBlock Text="" Width="5" />
                                            <TextBlock Text="{Binding LastName}" VerticalAlignment="Top" HorizontalAlignment="Left" 
                                                       TextWrapping="NoWrap" />
                                        </StackPanel>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="Förrättarkod">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                         <TextBlock Text="{Binding MinisterCode}" VerticalAlignment="Top" HorizontalAlignment="Left" 
                                                    TextWrapping="NoWrap" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="Telefon">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                         <TextBlock Text="{Binding PhoneNumber}" VerticalAlignment="Top" HorizontalAlignment="Left" TextWrapping="NoWrap" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="Förordnande">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding AssignmentStartDate, Converter={StaticResource dateTimeConverter}}" 
                                                       VerticalAlignment="Top" HorizontalAlignment="Left" TextWrapping="NoWrap" />
                                            <TextBlock Text="/" Padding="5,0,5,0" VerticalAlignment="Top" HorizontalAlignment="Center" TextWrapping="NoWrap">
                                                <TextBlock.Style>
                                                    <Style>
                                                        <Style.Triggers>
                                                            <DataTrigger Binding="{Binding AssignmentStartDate, Converter={StaticResource visibilityConverter}}" Value="{x:Null}">
                                                                <Setter Property="TextBlock.Visibility" Value="Hidden" />
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                    </Style>
                                                </TextBlock.Style>
                                            </TextBlock> 
                                            <TextBlock Text="{Binding AssignmentEndDate, Converter={StaticResource dateTimeConverter}}" 
                                                       VerticalAlignment="Top" HorizontalAlignment="Left" TextWrapping="NoWrap" />
                                        </StackPanel>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="Sär">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                         <TextBlock Text="{Binding IsSpecialAssignment}" VerticalAlignment="Top" HorizontalAlignment="Center" Width="30" TextWrapping="NoWrap" />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>

        </Grid>        
        
    </GroupBox>
</UserControl>
